package haitao.numberpicker.city;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.example.city2.R;
import com.haitao.glide.GlideImageLoader;
import com.haitao.glide.GlideImageView;
import com.haitao.glide.progress.CircleProgressView;
import com.haitao.glide.progress.OnProgressListener;
import com.haitao.glide.transformation.BlurTransformation;

import haitao.photobrowser.ui.PhotoViewActivity;

/**
 * @author by sunfusheng on 2017/6/3.
 */
public class MainActivity extends Activity {

    GlideImageView image11;
    GlideImageView image12;
    GlideImageView image14;

    GlideImageView image21;
    GlideImageView image23;
    GlideImageView image24;

    GlideImageView image31;
    CircleProgressView progressView1;
    ImageView image32;
    CircleProgressView progressView2;

    GlideImageView image41;


    String url1 = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1497688355699&di=ea69a930b82ce88561c635089995e124&imgtype=0&src=http%3A%2F%2Fcms-bucket.nosdn.127.net%2Ff84e566bcf654b3698363409fbd676ef20161119091503.jpg";
    String url3 = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1529402445474&di=b5da3b2f6a466e618e1e32d4dd2bda4d&imgtype=0&src=http%3A%2F%2F2b.zol-img.com.cn%2Fproduct%2F133_500x2000%2F801%2Fce21ke76FRh4A.jpg";

    String gif2 = "http://5b0988e595225.cdn.sohucs.com/images/20171202/a1cc52d5522f48a8a2d6e7426b13f82b.gif";
    String gif3 = "http://img.zcool.cn/community/01d6dd554b93f0000001bf72b4f6ec.jpg";

    public static final String cat = "https://raw.githubusercontent.com/sfsheng0322/GlideImageView/master/resources/cat.jpg";

    public static final String girl = "https://raw.githubusercontent.com/sfsheng0322/GlideImageView/master/resources/girl.jpg";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        image11 = (GlideImageView) findViewById(R.id.image11);
        image12 = (GlideImageView) findViewById(R.id.image12);
        image14 = (GlideImageView) findViewById(R.id.image14);

        image21 = (GlideImageView) findViewById(R.id.image21);
        image23 = (GlideImageView) findViewById(R.id.image23);
        image24 = (GlideImageView) findViewById(R.id.image24);

        image31 = (GlideImageView) findViewById(R.id.image31);
        progressView1 = (CircleProgressView) findViewById(R.id.progressView1);
        image32 = (ImageView) findViewById(R.id.image32);
        progressView2 = (CircleProgressView) findViewById(R.id.progressView2);

        image41 = (GlideImageView) findViewById(R.id.image41);


        image11.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String[] strs =new String[]{girl,cat,url3};
                Intent intent =new Intent(MainActivity.this, PhotoViewActivity.class);
                intent.putExtra(PhotoViewActivity.URL_ARRAY,strs);
                intent.putExtra(PhotoViewActivity.INDEX,1);
                startActivity( intent);
            }
        });

        image31.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String[] strs =new String[]{girl };
                Intent intent =new Intent(MainActivity.this, PhotoViewActivity.class);
                intent.putExtra(PhotoViewActivity.URL_ARRAY,strs);
                intent.putExtra(PhotoViewActivity.INDEX,1);
                startActivity( intent);
            }
        });
        image32.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String[] strs =new String[]{cat};
                Intent intent =new Intent(MainActivity.this, PhotoViewActivity.class);
                intent.putExtra(PhotoViewActivity.URL_ARRAY,strs);
                intent.putExtra(PhotoViewActivity.INDEX,1);
                startActivity( intent);
            }
        });
        image41.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String[] strs =new String[]{cat};
                Intent intent =new Intent(MainActivity.this, PhotoViewActivity.class);
                intent.putExtra(PhotoViewActivity.URL_ARRAY,strs);
                intent.putExtra(PhotoViewActivity.INDEX,1);
                startActivity( intent);
            }
        });



        line1();
        line2();
        line3();
        line4();
    }

    private void line1() {
        image11.enableState(true).load(url1);
        image12.loadCircle(url1);
        image14.load(url3, R.drawable.image_loading, 10);
    }

    private void line2() {
        image21.centerCrop().load(gif3, R.drawable.image_loading, 10);
        image23.fitCenter().loadCircle(gif3);
        image24.fitCenter().loadDrawable(R.drawable.gif_robot_walk);
    }

    private void line3() {

        GlideImageLoader.create(image31)
                .listener(new OnProgressListener() {
                    @Override
                    public void onProgress(int state, int percentage) {
                        if (state==LOAD_ING){
                            progressView1.setVisibility(View.VISIBLE);
                            progressView1.setProgress(percentage);
                        } else {
                            progressView1.setVisibility(View.GONE);
                        }
                    }
                })
                .centerCrop()
                .error(R.drawable.image_load_err)
                .placeholder(R.color.placeholder)
                .loadImage(girl);



        GlideImageLoader.create(image32)
                .listener(new OnProgressListener() {
                    public void onProgress(int state, int percentage) {
                        if (state==LOAD_ING){
                            progressView2.setVisibility(View.VISIBLE);
                            progressView2.setProgress(percentage);
                        } else {
                            progressView2.setVisibility(View.GONE);
                        }
                    }
                })
                .error(R.drawable.image_load_err)
                .placeholder(R.color.placeholder)
                .loadImage(cat);

    }

    private void line4() {
        image41.fitCenter().load(url3, R.drawable.image_loading, new BlurTransformation(this, 25, 1));
    }


}
